<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>航空公司走势对比-航线——恒拓运价魔方</title>
	<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/jquery-1.6.4.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
	<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/FusionCharts/FusionCharts.js"></script>
	<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/common.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
	
 	<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
	<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
	<!-- 圆角文本框 -->
	<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	
	
	
	<script type="text/javascript">
		$(function(){
			$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity});
			$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity});
			//$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList,'changeDoFusion':function(){}});
			//$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList,'changeDoFusion':function(){}});
			$("#depCity").css({color:'black'});
			$("#arrCity").css({color:'black'});
			$('#flightStartDate').val(generateTimeByFutrueDay(0));
			$('#flightEndDate').val(generateTimeByFutrueDay(30));
			
			
			$("#futureDay").click(function(){//未来天数被点击
				$('#flightStartDate').val("");
				$('#flightEndDate').val("");
				$("input[name='flightDateRadio'][type='radio'][value='2']").attr('checked',true);
			});
			$("#flightStartDate").click(function(){//出发/到达城市被点击
				$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
				$("#futureDay").val("");
				if($(this).val()=="" && $("#flightEndDate").val()=="" ){
					$('#flightStartDate').val(generateTimeByFutrueDay(0));
					$('#flightEndDate').val(generateTimeByFutrueDay(30));
				}
			});
			$("#flightEndDate").click(function(){//出发/到达城市被点击
				$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
				$("#futureDay").val("");
				if($(this).val()=="" && $("#flightStartDate").val()==""){
					$('#flightStartDate').val(generateTimeByFutrueDay(0));
					$('#flightEndDate').val(generateTimeByFutrueDay(30));
				}
			});
			
			
			$("input[name='flightDateRadio'][type='radio']").change(function(){
				if($(this).val()==1){
					$("#futureDay").val("");
					$('#flightStartDate').val(generateTimeByFutrueDay(0));
					$('#flightEndDate').val(generateTimeByFutrueDay(30));
				}else{
					$('#flightStartDate').val("");
					$('#flightEndDate').val("");
				}
			});
			
			$("input[name='periodsRadio'][type='radio']").change(function(){
				if($(this).val()==1){
					$("input[name='periods'][type='checkbox']").each(function(){
						$(this).attr('checked',true);
					});
					$("#selfStartPeriods").val("");
					$("#selfEndPeriods").val("");
				}else{
					$("input[name='periods'][type='checkbox']").each(function(){
						$(this).attr('checked',false);
					});
				}
			});
			$("input[name='periods'][type='checkbox']").each(function(){
				$(this).click(function(){
					$("input[name='periodsRadio'][type='radio'][value='1']").attr("checked",true);
					$("#selfStartPeriods").val("");
					$("#selfEndPeriods").val("");
				});
			});
			
			$("#selfStartPeriods").click(function(){
				$("input[name='periodsRadio'][type='radio'][value='2']").attr("checked",true);
				$("input[name='periods'][type='checkbox']").each(function(){
						$(this).attr('checked',false);
					});
			});
			$("#selfEndPeriods").click(function(){
				$("input[name='periodsRadio'][type='radio'][value='2']").attr("checked",true);
				$("input[name='periods'][type='checkbox']").each(function(){
						$(this).attr('checked',false);
					});
			});
		});
	
		//查询的验证
		function queryValidate(){
			
			if(validateFlightCity()==true 
					&& validateFlightDate()==true && validateCompareCompany()==true && validatePeriods()==true){
				ajaxLoad();
			}
		}
		//验证航班
		function validateFlightCity(){
			var depCity =$('#depCity').val();
		    var arrCity =$('#arrCity').val();
		    if(depCity==''||depCity=='中文/拼音' || arrCity==''||arrCity=='中文/拼音'){
				    alert("请先选择航线！");
			        return false;	     
			}
		    if(depCity == arrCity){
		    	alert("出发城市 和 到达城市 不能相同");
		    	return false;
		    }
		    return true;
		}
		//验证航班日期
		function validateFlightDate(){
			var value=$("input[name='flightDateRadio'][type='radio']:checked").val();
			if(value=='1'){
				var startdate = $('#flightStartDate').val();
				var enddate = $('#flightEndDate').val();
				
				if(startdate=="" || enddate==""){
					alert("您选择的是按【航班日期】查询，请输入填写完整正确的查询日期");
					return false;
				}	
				var s_date = new Date(startdate.replace(/-/g,"/"));
			    var e_date = new Date(enddate.replace(/-/g,"/"));
			    var time1 = s_date.getTime();
				var time2 = e_date.getTime();
				if(time1>time2){
					alert("航班日期起始时间不能大于航班结束时间");
					return false;
				}
			}else if(value=='2'){//未来天数
				var futureDays =$('#futureDay').val();
				if(futureDays==""){
					alert("您选择的是按【未来天数】查询，请输入未来天数");
					return false;
				}
				if(futureDays > 30){
					alert("请输入不多于未来30天(包含本日)的天数");
					return false;
				}
			}else{
				return false;
			}
			return true;
		}
		//验证时间段
		function validatePeriods(){
			var value=$("input[name='periodsRadio'][type='radio']:checked").val();
			if(value==1){//选择定义好的时间
				if($("input[name='periods'][type='checkbox'][checked!='true']").length==
					$("input[name='periods'][type='checkbox']").length){//没选择的数量等于总数量
					alert("请至少选择一个出发时段");
					return false;
				}
			}else{
				var start=$("#selfStartPeriods").val();
				var end=$("#selfEndPeriods").val();
				var reg=/^[0-9]|[1-9][0-9]$/;
				if(reg.test(start)==false || reg.test(end)==false){
					alert("请填写正确的时间段");
					return false;
				}
				if(parseInt(start)<0 || parseInt(end)<parseInt(start) ){
					alert("结束时间段不能小于开始时间段");
					return false;
				}
				if(parseInt(end)>24){
					alert("不能超过24小时");
					return false;
				}
				
			}
			return true;
		}
		
		//验证要比较的公司
		function validateCompareCompany(){
			if($("input[name='comparedCompanyHbaseKeys'][type='checkbox'][checked!='true']").length==
					$("input[name='comparedCompanyHbaseKeys'][type='checkbox']").length){//没选择的数量等于总数量
				alert("请选择要比较的比较公司");
				return false;
			}
			return true;
		}
		
		function ajaxLoad(){
			var url="<%=request.getContextPath() %>"+"/airCompanyTrendContrastLineAction!analyse.action";
			$("#compareCompanyHbaseKey").attr("disabled",false);
			$.ajax({
				url:url,
				data:$("#queryForm").serialize(),
				type : "POST",
				cache : false, 
				async : true,
			    dataType:'html',
			    beforeSend:function(){
			    	FDCWait.show();
			    },
			    success:function(data){
			    	var chart = new FusionCharts("<%=request.getContextPath() %>/FusionCharts/MSLine.swf", "chartID", 990, "450");
					chart.setDataXML(data);
					chart.render("chartContainer");
			    },
			    error:function(){ alert("查询失败，请联系管理员！");},
			    complete:function(){ 
			    	$("#compareCompanyHbaseKey").attr("disabled",true);
			    	FDCWait.hide();
			    }
			});
		}
		
		/**
		 * 生成一个未来天数的日期字符串
		 */
		function generateTimeByFutrueDay(day){
			if(!/^\d+$/.test(day)){day=0;}
			var now=new Date();
			now.setDate(now.getDate()+day);
			var year=now.getFullYear();
			var month=now.getMonth()+1;
			month=month<10?"0"+month:month+"";
			var date=now.getDate();
			date=date<10?"0"+date:date+"";
			return year+"-"+month+"-"+date;
		}
		
		//重置form
	function resetForm(){
		$('#flightStartDate').val(generateTimeByFutrueDay(0));
		$('#flightEndDate').val(generateTimeByFutrueDay(30));
		$("#depCity").val("中文/拼音");
		$("#arrCity").val("中文/拼音");
		$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
		$("input[name='periodsRadio'][type='radio'][value='1']").attr('checked',true);
		$("#futureDay").val("");
		$("input[name='periods'][type='checkbox']").each(function(){
			$(this).attr("checked",true);
		});
		$("#selfStartPeriods").val("");
		$("#selfEndPeriods").val("");
		$("#dataSourceHbaseKey")[0].selectedIndex=0;
		$("input[name='comparedCompanyHbaseKeys'][type='checkbox']").each(function(){
			$(this).attr("checked",true);
		});
	}
		
	</script>
	
</head>

<body>
<jsp:include page="../../inc/treelist3.jsp"></jsp:include>
<jsp:include page="/pages/system/feedback/feedback.jsp" ></jsp:include>
<div class="main main_max">
	<div class="sideBar">
		<div class="box">
			<div class="location">当前位置： 实时运价走势 &gt; 航线走势对比</div>
		</div>
	</div>
	<div class="cls"></div>
	<div class="content"><div class="form_table_tltle">查询条件 </div>
		<form id="queryForm"  method="post">
			<table cellSpacing=0 cellPadding=0 width="100%" border=0 class="form_table">
	 		<TR>
	   			<TD width="120" height="26" class="left" style="text-align:left">航空公司：</TD>
	            <TD colspan="3">
			    	<%-- 整个select模版，有抓取的所有航空公司，目前锁定自己所在的航空公司 --%>
			      	<select class="easyui-combobox" name="compareCompanyHbaseKey" style="width: 150px;" id="compareCompanyHbaseKey" disabled='true'>
						<c:forEach var="item" items="${crawlCompanys}">
							<option value="${item.hbaseKey}"
							<c:if test="${item.hbaseKey==sessionScope.currentUser.sourceKey}">selected='selected' </c:if>
							>${item.name}</option>
						</c:forEach>
					</select>
					<span style="color: #ff0000">*</span>
	   			</TD>
	  		</TR>
	  		<TR>
	    		<TD width="120" height="26" class="left" style="text-align:left">航&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;线：</TD>
	   			<TD>
	   			<jsp:include page="/inc/flightSelect.jsp"></jsp:include>
	     		 <%-- 	<input type="text" name="depCity" style="width:100px" id="depCity" readonly='readonly'/>
			    	<span>至</span>
			        <input type="text" name="arrCity" style="width:100px" id="arrCity" readonly='readonly'/>
	     		    <span style="color: #ff0000">*</span> --%>
	    		</TD><td></td><td></td>
	    	</TR>
	        <TR>
	            <TD height="26" class="left" style="text-align:left">
	                <input  name="flightDateRadio" value="1" type="radio" checked="checked">航班日期：
	            </TD>
	            <TD>
	             	<input name="flightStartDate" type="text" id="flightStartDate" style="width:100px"
				      onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'${maxDate}'});">
				    <span>至</span>
				    <input name="flightEndDate" type="text" id="flightEndDate" style="width:100px" 
				      onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'${maxDate}'});">
				    <span style="color: #ff0000">*</span>
		        </TD>
	  	   		<TD class="left" style="text-align:left">
			      <input name="flightDateRadio"   type="radio" value="2">未来天数：</TD>
			 	<TD>
			 	  <input type="text" style="width:30px" maxlength="2" 
			 	    name="futureDay" id="futureDay"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">天
			 	</TD>
	  		</TR>
	  		<TR>
	    		<TD class="left" style="text-align:left">
	    			<input name="periodsRadio" value="1" type="radio" checked="checked">出发时段：
	    		</TD>
	    		<TD>
					<input type="checkbox" name="periods" value="AM" checked="checked"/>上午
					<input type="checkbox" name="periods" value="MD" checked="checked"/>中午
					<input type="checkbox" name="periods" value="PM" checked="checked"/>下午
					<input type="checkbox" name="periods" value="ND" checked="checked"/>晚上
				</TD>
	  			<TD class="left" style="text-align:left">
	  			 	<input name="periodsRadio" value="2" type="radio">自定义：
	  			</TD>
	  			<TD>
	  	   			 <input name="selfStartPeriods" type="text" id="selfStartPeriods" maxlength="2" style="width:30px"  value="${depTimeHour}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;：
	  	   			 <input name="selfEndPeriods" type="text" id="selfEndPeriods" maxlength="2" style="width:30px" value="${arrTimeHour}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;
	  	 		</TD>
	 		 </TR>
	         <TR>
	  	         <TD height="26" class="left" style="text-align:left">比较公司：</TD>
		  	     <TD>
					
					<!-- 仅仅作为前台取值的临时隐藏于，后台无影响 -->
					<%-- 作为比较公司需要去掉自己 --%>
					<c:forEach var="item" items="${crawlCompanys}" varStatus="status" >
						<c:if test="${item.hbaseKey!=sessionScope.currentUser.sourceId}">
							<input type="hidden" value="${item.hbaseKey}-${item.name}" tempAttr="temp_contrastCompanys_hidden"/>
						</c:if>
					</c:forEach>
					<table style="margin:10px 0 10px 0;border:0px;" id="temp_table_ken"></table>
					<%-- 这个js是为了动态的生成比较的航空公司，现在是四个，以后就不知道了，标注一下 --%>
					<script type="text/javascript">
						var table=$("#temp_table_ken");
						var rowSize=4;//一行容纳多少个公司，动态的生成表格
						var index=0;
						$("input[type='hidden'][tempAttr='temp_contrastCompanys_hidden']").each(function(){
							index++;
							if(index%rowSize==1){
								table.append("<tr></tr>");
							}
							$("tr:last",table).append("<td style='padding:5px 5px 5px 0px;border-bottom:0px;'>"
							+"<input type='checkbox' name='comparedCompanyHbaseKeys' value='"+this.value.split('-')[0]+"'/>&nbsp&nbsp&nbsp"+this.value.split("-")[1]
							+"</td>");
						});
					</script>
				</TD><TD></TD><TD></TD>
	        </TR>
	  
			<TR>
			    <TD class="left" style="text-align:left">数据来源：</TD>
			    <TD colspan="3" align="left">
			     	<select class="easyui-combobox" name="dataSourceHbaseKey" style="width: 150px;" id="dataSourceHbaseKey">
			           <option value="" selected="selected">航空公司官网</option>
			           <c:forEach var="item" items="${crawlChannels}">
						 <option value="${item.hbaseKey}">${item.name}</option>
					   </c:forEach>        
					</select>
					<span style="color: #ff0000">*</span>
				</TD>
			</TR>
	  
	  		<TR>
			    <TD style="text-align:center;height:35px;" colspan="4">
			         <input type="button" value="" class="btn01"  onclick="queryValidate()"/>
			         <input type="button" name="Submit222" value="" class="btn02" onclick="resetForm()" />
			    </TD>
	  		</TR>
		</TABLE>
		</form>
		<p></p><p></p>
		
		<div id='chartContainer'></div>
	</div>
</div>
<br></br>  <br></br>  <br></br>  <br></br>  <br></br>
<jsp:include page="../../inc/footer2.jsp"></jsp:include> 
</body>
</html>

